package com.core.multithreading.a;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Sunil
 */
public class Consumer extends Thread {

    List<String> jobs;

    public Consumer(List<String> jobs, String name) {
        this.jobs = jobs;
        setName(name);
    }

    public void run() {
        while (true) {
            synchronized (jobs) {
                try {
                    if (jobs.isEmpty()) {
                        jobs.wait();
                    } else {
                        System.out.println(getName() + " : REMOVING : " + jobs.remove(0));
                    }
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    }
}